package lyq.zkhw;

import org.I0Itec.zkclient.ZkClient;

public class ZKHWServer {

    private final static String driver = "com.mysql.cj.jdbc.Driver" ;
    private  final static String url="jdbc:mysql://localhost:3306/my?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
    private  String user;
    private  String password;


    private ZkClient zkClient = null;
    private void connetZK(){
        zkClient = new ZkClient("linux121:2181,linux122:2181,linux123:2181");
        if (!zkClient.exists("/mysqlConfs")){
            zkClient.createPersistent("/mysqlConfs");
        }
    }

    public void myconf(String user,String password){
//        String path = zkClient.createEphemeralSequential("/mysqlConfs/mysql","\"user\":\""+user+"\",\"password\" =\""+password+"\",\"driver\" =\""+driver+"\",\"url\" =\""+url+"\"");
        String path = zkClient.createEphemeralSequential("/mysqlConfs/mysql",user+","+password+","+driver+","+url);
        System.out.println("---->>> 服务器注册成功， user="+user+";password ="+password+";\n driver ="+driver+";url ="+url+";节点\n" +
                "路路径信息=" +path);
    }

    public static void main(String[] args) throws InterruptedException {
        ZKHWServer zkhwServer = new ZKHWServer();
        zkhwServer.connetZK();
        zkhwServer.myconf(args[0], args[1]);
//        new TimeServer(Integer.parseInt(args[1])).start();
        Thread.sleep(Integer.MAX_VALUE);
    }




}
